﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FirstWebSite.AuthenticationServiceClient;

namespace FirstWebSite
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// Handles the Click event of the LoginButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            AuthenticationServiceClient.AuthenticationServiceClient client = new FirstWebSite.AuthenticationServiceClient.AuthenticationServiceClient();
            LoginRequest loginRequest = new LoginRequest();
            loginRequest.User = new User();
            loginRequest.User.LoginId = UserNameTextBox.Text;
            loginRequest.User.Password = PasswordTextBox.Text;
            LoginResponse loginResponse = client.Login(loginRequest);

            if (null == loginResponse.Fault && null != loginResponse.User)
            {
                Session["User"] = loginResponse.User;
                Response.Redirect("FirstDefault.aspx");
            }
        }
    }
}
